import {Global, Module} from '@nestjs/common';
import {CommonService} from './common.service';
import {ConfigModule, ConfigService} from "@nestjs/config";
import {DbModule} from "@libs/db";
import config from './configs/index'
import {JwtModule} from "@nestjs/jwt";
import {EnvEnum} from "@app/common/enum/envEnum";

@Global()
@Module({
  imports: [
    ConfigModule.forRoot({
      load: [config],
      isGlobal: true,
    }),
    DbModule,
    JwtModule.registerAsync({
      useFactory(configService: ConfigService) {
        return {
          secret: configService.get('env')[EnvEnum.secret] || 'kjdafjdskfioczxuiovjdsfjkds'
        }
      },
      inject: [ConfigService]
    })
  ],
  providers: [CommonService],
  exports: [CommonService, JwtModule],
})
export class CommonModule {
}
